package pojo.cat;

import java.util.*;

public class GoodsCat {
    private List<ShowGood> goodlist = new ArrayList<>();

    private double sum;

    public String addGoodCat(ShowGood showGood) {
        if (showGood.getNum() > showGood.getTgoods().getStock()) {
            return "库存不足";
        }

        boolean is = true;
        for (ShowGood good : goodlist) {
            if (good.getTgoods().getId() == showGood.getTgoods().getId()) {
                if (good.getNum() + showGood.getNum() > good.getTgoods().getStock()) {
                    return "库存不足";
                } else {
                    good.setNum(showGood.getNum() + good.getNum());
                    is = false;
                    return "添加成功！";
                }
            }
        }

        if (is) {
            goodlist.add(showGood);
            return "添加成功！";
        }

        return "添加异常！,请重试";

    }

    public void js() {
        sum = 0;
        for (ShowGood showGood : goodlist) {
            sum += showGood.getPrice();
        }
    }

    public List<ShowGood> getGoodlist() {
        return goodlist;
    }

    public void setGoodlist(List<ShowGood> goodlist) {
        this.goodlist = goodlist;
    }

    public double getSum() {
        return sum;
    }

    public void setSum(double sum) {
        this.sum = sum;
    }

    public GoodsCat() {
    }

    public GoodsCat(List<ShowGood> goodlist, double sum) {
        this.goodlist = goodlist;
        this.sum = sum;
    }
}
